package com.zzedu.web.controller;

import com.zzedu.common.utils.StringUtils;
import com.zzedu.enmuns.ConfigEnums;
import com.zzedu.result.Result;
import com.zzedu.result.ResultEnum;
import com.zzedu.stu.req.AppVersion;
import com.zzedu.system.service.ISysConfigService;
import com.zzedu.utils.BaseReq;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 版本号
 */
@RestController
public class AppVersionController {

    @Autowired
    ISysConfigService sysConfigService;

    /**
     * 获取版本号
     *
     * @param baseRequest
     * @return
     */
    @PostMapping("/getVersion")
    public Result<String> getVersion(@Validated @RequestBody BaseReq<AppVersion> baseRequest) {
        AppVersion appVersion = baseRequest.getData();
        String key = ConfigEnums.APP_VERSION.getCode();
        if (null != appVersion && StringUtils.isNotBlank(appVersion.getOs())) {
            key = key + "." + appVersion.getOs();
        }
        Result<String> result = new Result<>();
        result.setResultMessage(ResultEnum.SUCCESS.getDesc());
        result.setResultCode(ResultEnum.SUCCESS.getCode());
        result.setData(sysConfigService.selectConfigByKeyCache(key));
        return result;
    }
}
